package com.nowcoder.Offer.Array;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * 递增序列查找目标和的数对
 */
public class findTwoSum {
    public ArrayList<Integer> FindNumbersWithSum(int [] array, int sum) {
        int l=0, r=array.length-1;
        while(l<r){
            if(array[l] + array[r] == sum) return new ArrayList<>(Arrays.asList(array[l],array[r]));
            else if(array[l] + array[r] < sum) l++;
            else r--;
        }
        return new ArrayList<>();
    }

    @Test
    public void test(){
        int[] arr = {1,2,4,7,11,15};
        System.out.println(FindNumbersWithSum(arr,15));
    }
}
